#include "ai.h"
#include <windows.h>

Ai::Ai()
{
	setMove(ZERO);
}

void Ai::setMove(int a_columnDrop)
{
	m_columnDrop = a_columnDrop;
}

int Ai::getMove()
{
	return m_columnDrop;
}

void Ai::setPlayerColumn(int a_playerColumn)
{
	m_playerColumn = a_playerColumn;
}
	
int Ai::getPlayerColumn()
{
	return m_playerColumn;
}

	
void Ai::setPlayerRow(int a_playerRow)
{
	m_playerRow = a_playerRow;
}

int Ai::getPlayerRow()
{
	return m_playerRow;
}

void Ai::trackPlayerMove(int row, int col)
{
	setPlayerColumn(col);
	setPlayerRow(row);
}

void Ai::randomStrategy()
{
	int strategy = (rand() % 3 + 1);
	switch (strategy)
	{
	case 1:	randomMove();		break;
	case 2:	blockOpponent();	break;
	case 3: goForWin();			break;
	}

}
void Ai::randomMove()
{
	setMove(rand() % BOARD_WIDTH);
}

void Ai::blockOpponent()
{
	//  the following will allow the ai to attempt to block right first, then left, then top

	if (getPlayerColumn()+1 < (BOARD_WIDTH))
	{
		setMove(getPlayerColumn()+1);
	}
	else if(getPlayerColumn()-1 > ZERO)
	{
		setMove(getPlayerColumn()-1);
	}
	else if(getPlayerRow() > ZERO)
	{
		setMove(getPlayerColumn());
	}
}
	
void Ai::goForWin()
{
	// getMove is the tracker for the cpu's last move based on column only
	getMove();

	//the a.i. will try to attempt a win to the right first, then left
	//if the piece attempts to move out of bounds then it will try another direction

	//the ai should drop a piece on top of it's previous piece if it can't move to the left or right
	if (getMove()+1 < (BOARD_WIDTH))
	{
		setMove(getMove()+1);
	}
	else if(getMove()-1 > ZERO)
	{
		setMove(getMove()-1);
	}

}